package MyDate;
import java.time.Month;

import java.time.LocalDate;
import java.time.Year;
import java.time.YearMonth;
public class Mydate {
    public int year;
    public int month;
    public int day;

    public Mydate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }
//判断是否是闰年
    public boolean isLeapYear(int age) {
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            return true;
        } else {
            return false;
        }
    }
//月份转换
    public void monthName(int monthNumber) {


        // 检查月份数值是否有效
        if (monthNumber < 1 || monthNumber > 12) {
            System.out.println("无效的月份数值。月份数值必须在1到12之间。");
        }

        Month month = Month.of(monthNumber); // 将数值转换为Month枚举
        String monthName = month.name(); // 获取月份对应的英文名称

        // 英文月份名称是大写的，如果需要小写，可以转换
        String monthNameLowerCase = monthName.toLowerCase();

        System.out.println("月份数值 " + monthNumber + " 对应的英语单词是: " + monthNameLowerCase);


    }


        // 返回这个月的总天数
        public  int getToDaysOfMonth(int year, int month) {
            YearMonth yearMonth = YearMonth.of(year, month);
            return yearMonth.lengthOfMonth();
        }

        // 返回这一年的总天数
        public  int getTotalDaysOfYear(int year) {
            Year yearObj = Year.of(year);
            return yearObj.isLeap() ? 366 : 365;
        }

        // 返回这一天是当年的第几天
        public  int daysOfTheYear(int year, int month, int day) {
            LocalDate date = LocalDate.of(year, month, day);
            return date.getDayOfYear();
        }

}
